package org.guegan.util.dircompare.util;

import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.regex.Pattern;

public class DefaultFileFilter implements FileFilter {

	private String filters;
	private List<Pattern> list = new ArrayList<Pattern>();
	
	private void initList() {
		if (list.size() == 0) {
			StringTokenizer st = new StringTokenizer(filters, ",");
			while (st.hasMoreTokens()) {
				Pattern pat = Pattern.compile(st.nextToken());
				list.add(pat);
			}
		}
	}
	
	public void setFilters(String filters) {
		this.filters = filters;
	}



	public String getFilters() {
		return filters;
	}
	
	@Override
	public boolean accept(File pathname) {
		boolean ret = true;
		initList();
		for (Pattern filter : list) {
			if (filter.matcher(pathname.getName()).matches()) {
				ret = false;
				break;
			}
		}return ret;
	}
	
}
